#include <limits.h>
#include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

bool isHappy(int n);
int n2pow(int n);

int main()
{
	return 0;
}

bool isHappy(int n)
{
	int slow = n, fast = n2pow(n);
	while (slow != fast) {
		if (slow == 1) return true;
		slow = n2pow(slow);
		fast = n2pow(n2pow(fast));
	}
	if (slow == 1) return true;
	return false;
}

int n2pow(int n)
{
	int sum = 0;
	while (n) {
		int remain = n % 10;
		n /= 10;
		sum += remain * remain;
	}
	return sum;
}
